package com.example.demo.day.config.learn.design.observable.x1;

import java.util.ArrayList;
import java.util.List;



public class Weather implements Observable {

    private float mTemperature;
    private float mHumidity;
    private float mPressure;

    private List<Observer> mObserver;

    public Weather() {
        mObserver = new ArrayList<>();
    }

    @Override
    public void registerObserver(Observer o) {
        mObserver.add(o);
    }

    @Override
    public void removeObserver(Observer o) {
        mObserver.remove(o);
    }

    @Override
    public void notifyObserver() {
        for (Observer o: mObserver) {
            //System.out.println(o.toString());
            o.onNotify(mTemperature, mHumidity, mPressure);
        }
    }

    public void serMeasurements(float temperature, float humidity, float pressure) {
        this.mTemperature = temperature;
        this.mHumidity = humidity;
        this.mPressure = pressure;
        notifyObserver();
    }
}
